package com.mrsltec.chat.controller;

import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.IBinder;

import com.mrsltec.chat.service.WebSocketClientService;

/**
 * Created by zhoumingrui on 2017/1/15.
 */

public class MainActivityController {
    Context context = null;

    private ServiceConnection conn = new ServiceConnection() {

        @Override
        public void onServiceDisconnected(ComponentName name) {
            // TODO Auto-generated method stub
        }

        @Override
        public void onServiceConnected(ComponentName name, IBinder service) {
            // TODO Auto-generated method stub这里面发送消息通过Service
            WebSocketClientService.WebSocketClientBinder binder = (WebSocketClientService.WebSocketClientBinder) service;
            binder.sendXxx("hahah");
        }
    };

    public void setContext(Context context) {
        this.context = context;
    }

    public boolean createService(){
        Intent intent = new Intent(context, WebSocketClientService.class);
        context.startService(intent);
        context.bindService(intent, conn, Context.BIND_AUTO_CREATE);
        return true;
    }
}
